package design.mode.singleton;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 懒汉式（有线程并发问题）
 */
public class LazySimpleSingleton {

    private AtomicLong id = new AtomicLong();

    private static LazySimpleSingleton instance;

    private LazySimpleSingleton() {

    }

    /**
     * 存在并发问题
     *
     * @return
     */
    public static synchronized LazySimpleSingleton getInstance() {
        if (instance == null) {
            instance = new LazySimpleSingleton();
        }
        return instance;
    }

    public long getId() {
        return id.incrementAndGet();
    }
}
